home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / reactor / code.lua next >
Text File  |  2005-07-16  |  8KB  |  250 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky07.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room.pldpred = random(2)
  16.         room.zacni = 0
  17.         room.tyce = random(5) + 4
  18.  
  19.         return function()
  20.             if room.pldpred == 1 and room.zacni == 0 or room.pldpred == 0 and room.zacni == 1 then
  21.                 room.pldpred = -1
  22.                 if room.zacni == 0 then
  23.                     addm(random(30) + 20, "rea-m-proboha")
  24.                 else
  25.                     addm(random(100) + 50, "rea-m-proboha")
  26.                 end
  27.                 addv(14, "rea-v-coto")
  28.                 addm(6, "rea-m-nevim")
  29.                 planSet(pld, "smutny", 60)
  30.                 pld:planDialog(3, "rea-x-pldik")
  31.             end
  32.             if room.zacni == 0 then
  33.                 room.zacni = 1
  34.                 if room.pldpred == 1 then
  35.                     addm(random(150) + 60, "rea-m-comyslis")
  36.                 else
  37.                     addm(random(30) + 20, "rea-m-comyslis")
  38.                 end
  39.                 addv(6, "rea-v-patrne")
  40.                 addv(random(130) + 30, "rea-v-ledaze")
  41.                 addm(random(70), "rea-m-mohl")
  42.                 addv(6, "rea-v-tozni")
  43.                 addm(random(200) + 20, "rea-m-anebo")
  44.                 addv(2, "rea-v-acoby")
  45.                 addm(12, "rea-m-cojavim")
  46.                 addv(random(20) + 2, "rea-v-radeji")
  47.                 addm(5, "rea-m-jakmuzes")
  48.                 addv(4, "rea-v-kolik")
  49.                 addv(random(10) + 15, "rea-v-takvidis")
  50.             end
  51.             if isReady(small) and isReady(big) then
  52.                 if room.zacni == 1 and no_dialog() and tyc.padlo >= room.tyce and tyc:isTalking() then
  53.                     room.tyce = 1000
  54.                     addm(9, "rea-m-doufam")
  55.                     addv(5, "rea-v-nemudruj")
  56.                 end
  57.             end
  58.         end
  59.     end
  60.  
  61.     -- -------------------------------------------------------------
  62.     local function prog_init_tyc()
  63.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  64.  
  65.         tyc.padlo = 0
  66.         local tyce = {}
  67.         for index = 0, 12 do
  68.             tyce[index] = getModelsTable()[tyc.index + index]
  69.             tyce[index].pada = false
  70.         end
  71.  
  72.         return function()
  73.             local count = game_getCycles()
  74.             for index, model in pairs(tyce) do
  75.                 model.afaze = 2 - math.floor(math.mod(count, 6) / 2)
  76.                 model:updateAnim()
  77.             end
  78.             for pom1, model in pairs(tyce) do
  79.                 switch(model.dir){
  80.                     [dir_down] = function()
  81.                         model.pada = true
  82.                     end,
  83.                     default = function()
  84.                         if model.pada then
  85.                             model.pada = false
  86.                             tyc:talk("rea-x-reakttyc", VOLUME_FULL)
  87.                             tyc.padlo = tyc.padlo + 1
  88.                         end
  89.                     end,
  90.                 }
  91.             end
  92.         end
  93.     end
  94.  
  95.     -- -------------------------------------------------------------
  96.     local function prog_init_pld()
  97.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  98.  
  99.         pld.vlnit = 0
  100.         pld.del = 0
  101.         pld.ocko = 0
  102.         pld.smer = 0
  103.         pld.faze = 0
  104.         pld.smutny = 0
  105.  
  106.         return function()
  107.             switch(pld.dir){
  108.                 [dir_no] = function()
  109.                     if pld.vlnit == -1 then
  110.                         pld.vlnit = 8
  111.                     end
  112.                 end,
  113.                 [dir_down] = function()
  114.                     pld.vlnit = -1
  115.                 end,
  116.                 default = function()
  117.                     pld.vlnit = 8
  118.                 end,
  119.             }
  120.             if pld.vlnit > 0 then
  121.                 pld.smutny = 0
  122.             end
  123.             if pld.vlnit > 0 then
  124.                 if pld.del == 0 then
  125.                     if pld.vlnit < 3 then
  126.                         pld.del = 3
  127.                     elseif pld.vlnit < 6 then
  128.                         pld.del = 2
  129.                     else
  130.                         pld.del = 1
  131.                     end
  132.                     if random(2) == 0 then
  133.                         pld.afaze = math.mod(pld.afaze + 1, 4)
  134.                     else
  135.                         pld.afaze = math.mod(pld.afaze + 3, 4)
  136.                     end
  137.                     pld.vlnit = pld.vlnit - 1
  138.                     if pld.vlnit == 0 then
  139.                         pld.del = 0
  140.                     end
  141.                     if pld.vlnit == 0 then
  142.                         pld.afaze = 0
  143.                     elseif pld.vlnit == 1 then
  144.                         pld.afaze = 3
  145.                     end
  146.                 else
  147.                     pld.del = pld.del - 1
  148.                 end
  149.             elseif pld.smutny > 0 then
  150.                 if pld.ocko == 0 then
  151.                     if random(100) < 10 then
  152.                         pld.ocko = 3
  153.                     end
  154.                 end
  155.                 if pld.ocko > 0 then
  156.                     pld.ocko = pld.ocko - 1
  157.                 end
  158.                 if pld.ocko > 0 then
  159.                     pld.afaze = 15
  160.                 else
  161.                     pld.afaze = 14
  162.                 end
  163.                 pld.smutny = pld.smutny - 1
  164.             else
  165.                 if random(100) < 10 then
  166.                     pld.smer = 1 - pld.smer
  167.                 end
  168.                 switch(pld.faze){
  169.                     [0] = function()
  170.                         pld.afaze = 0
  171.                         if random(100) < 10 then
  172.                             pld.faze = 1
  173.                         end
  174.                     end,
  175.                     [5] = function()
  176.                         pld.afaze = 0
  177.                         pld.faze = 0
  178.                     end,
  179.                     default = function()
  180.                         if pld.faze == 1 or pld.faze == 4 then
  181.                             pld.faze = pld.faze + 1
  182.                             pld.afaze = 4
  183.                         elseif pld.faze == 2 or pld.faze == 3 then
  184.                             pld.faze = pld.faze + 1
  185.                             pld.afaze = 5
  186.                         end
  187.                     end,
  188.                 }
  189.                 switch(pld.afaze){
  190.                     [0] = function()
  191.                         if pld.smer == 1 then
  192.                             pld.afaze = 6
  193.                         end
  194.                     end,
  195.                     [4] = function()
  196.                         if pld.smer == 1 then
  197.                             pld.afaze = 7
  198.                         end
  199.                     end,
  200.                 }
  201.                 if pld.ocko == 0 then
  202.                     if random(100) < 10 then
  203.                         pld.ocko = 3
  204.                     end
  205.                 end
  206.                 if pld.ocko > 0 then
  207.                     pld.ocko = pld.ocko - 1
  208.                 end
  209.                 if pld.ocko > 0 then
  210.                     if pld.afaze == 0 then
  211.                         pld.afaze = 9
  212.                     else
  213.                         pld.afaze = pld.afaze + 6
  214.                     end
  215.                 end
  216.             end
  217.             pld:updateAnim()
  218.         end
  219.     end
  220.  
  221.     -- --------------------
  222.     local update_table = {}
  223.     local subinit
  224.     subinit = prog_init_room()
  225.     if subinit then
  226.         table.insert(update_table, subinit)
  227.     end
  228.     subinit = prog_init_tyc()
  229.     if subinit then
  230.         table.insert(update_table, subinit)
  231.     end
  232.     subinit = prog_init_pld()
  233.     if subinit then
  234.         table.insert(update_table, subinit)
  235.     end
  236.     return update_table
  237. end
  238. local update_table = prog_init()
  239.  
  240.  
  241. -- -----------------------------------------------------------------
  242. -- Update
  243. -- -----------------------------------------------------------------
  244. function prog_update()
  245.     for key, subupdate in pairs(update_table) do
  246.         subupdate()
  247.     end
  248. end
  249.  
  250.